<template>
    <div id="particulars">
        <v-detail :detailData="inputData" :inputConfig="inputConfig" :rules="rules" @changeData="changeData"
                  @pop="setdata" ref="input"></v-detail>
    </div>
</template>

<script>
    import detail from "commons/Detail";
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        name: "particulars",
        props: {
            inputData: {
                type: Object
            }
        },
        mixins: [baseMixin],
        data() {
            return {
                rules: {
                    storerkey: [
                        {required: true, trigger: 'blur'},
                    ],
                    bomsku: [
                        {required: true, trigger: 'blur'},
                    ],
                    sku: [
                        {required: true, trigger: 'blur'},
                    ],
                    ifbom: [
                        {required: true, trigger: 'blur'},
                    ],
                    sequence: [
                    {validator: this.verify1, trigger: 'blur'},
                ],
                num: [
                    {validator: this.verify1, trigger: 'blur'},
                ]
                },
                flag: true,
            }
        },
        computed: {
            inputConfig() {
                return [
                    [
                        {
                            type: "table",
                            label: this.$t('config.shipper'),
                            props: "storerkey",
                            tableConfig: [
                                {
                                    label: this.$t('config.shipper'),
                                    prop: "storerkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.company'),
                                    prop: "company",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.city'),
                                    prop: "city",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.provice'),
                                    prop: "state",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.postcode'),
                                    prop: "zip",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.contact'),
                                    prop: "contact",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.phone'),
                                    prop: "phone",
                                    input: "input",
                                },
                            ],
                            url: `/queryStorer/1/?/${this.$store.state.wms}`,
                            disabled: this.flag
                        },
                        {
                            type: "table",
                            label: this.$t('config.componentGoods'),
                            props: "bomsku",
                            tableConfig: [
                                {
                                    label: this.$t('config.sku'),
                                    prop: "sku",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "descr",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.shipper'),
                                    prop: "storerkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.packaging'),
                                    prop: "packkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.boxGroup'),
                                    prop: "cartongroup",
                                    input: "select",
                                    options: this.getOptions("queryCartonizationDropDown")
                                },
                                {
                                    label: this.$t('config.allocaStrategy'),
                                    prop: "strategykey",
                                    input: "select",
                                    options: this.getOptions("queryAllocatestrategyDropDown")
                                },
                                {
                                    label: this.$t('config.putawayStrategy'),
                                    prop: "putawaystrategykey",
                                    input: "select",
                                    options: this.getOptions("queryPutawaystrategyDropDown")
                                },
                                {
                                    label: this.$t('config.batchValidate'),
                                    prop: "lottablevalidationkey",
                                    input: "select",
                                    options: this.getOptions("queryLottablevalidationDropDown")
                                },
                                {
                                    label: this.$t('config.area'),
                                    prop: "putawayzone",
                                    input: "select",
                                    options: this.getOptions("queryPutawayzoneDropDown")
                                }
                            ],
                            url: `/querySkuOfStorerkey/?/${this.$store.state.wms}/${this.inputData.storerkey}`,
                            disabled: this.flag
                        },
                        {
                            type: "table",
                            label: this.$t('config.sku'),
                            props: "sku",
                            tableConfig: [
                                {
                                    label: this.$t('config.sku'),
                                    prop: "sku",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "descr",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.shipper'),
                                    prop: "storerkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.packaging'),
                                    prop: "packkey",
                                    input: "input",
                                },
                                {
                                    label: this.$t('config.boxGroup'),
                                    prop: "cartongroup",
                                    input: "select",
                                    options: this.getOptions("queryCartonizationDropDown")
                                },
                                {
                                    label: this.$t('config.allocaStrategy'),
                                    prop: "strategykey",
                                    input: "select",
                                    options: this.getOptions("queryAllocatestrategyDropDown")
                                },
                                {
                                    label: this.$t('config.putawayStrategy'),
                                    prop: "putawaystrategykey",
                                    input: "select",
                                    options: this.getOptions("queryPutawaystrategyDropDown")
                                },
                                {
                                    label: this.$t('config.batchValidate'),
                                    prop: "lottablevalidationkey",
                                    input: "select",
                                    options: this.getOptions("queryLottablevalidationDropDown")
                                },
                                {
                                    label: this.$t('config.area'),
                                    prop: "putawayzone",
                                    input: "select",
                                    options: this.getOptions("queryPutawayzoneDropDown")
                                }
                            ],
                            url: `/querySkuOfStorerkey/?/${this.$store.state.wms}/${this.inputData.storerkey}`,
                            disabled: this.flag
                        }
                    ],
                    [
                        {
                            type: "input",
                            label: this.$t('config.sequence'),
                            props: "sequence",
                        },
                        {
                            type: "input",
                            label: this.$t('config.num'),
                            props: "num",
                        },
                        {
                            type: "select",
                            label:  this.$t('config.onlyBom'),
                            props: "ifbom",
                            options: [
                                {code: 'Y', description: this.$t('code.yes')},
                                {code: 'N', description: this.$t('code.no')}
                            ]
                        }
                    ],
                    [
                        {
                            type: "textarea",
                            label:  this.$t('app.remark'),
                            props: "notes",
                        }
                    ],
                ]
            }
        },
        methods: {
            setdata(data, id, close, listId) {
                if (id == "0") {
                    this.inputData.storerkey = data.storerkey;
                } else if (id == "1") {
                    this.inputData.bomsku = data.sku;
                } else if (id == "2") {
                    this.inputData.sku = data.sku;
                }
                close(false);
            },
            changeData(obj, prop, data) {
                if (prop == "storerkey") {
                    this.$api.get(`/isExists/1/${data}/${this.$store.state.wms}`).then(res => {
                        
                            if (res.bean <= 0) {
                                this.$message.error(this.$t('config.nullShipper') + data);
                                this.inputData[prop] = "";
                            }
                        
                    }).catch(e => {
                        this.$message.error(e);
                    })
                }

            },
            verify1(rule, value, callback){
            if (value === '') {
                callback(new Error());
            } else {
                var re = /^[0-9]*$/;
                let te = value;
                let flag = re.test(te)
                if (flag) {
                    if (value < 0) {
                        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                    callback(new Error());
                }
            }
        },
        },
        mounted() {
            if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                if (data.newFlag) {
                    this.flag = false;
                } else {
                    this.flag = true;
                }
            } else if (this.$store.state.newFlag) {
                this.flag = false;
            } else {
                this.flag = true;
            }
        },
        watch: {},
        components: {
            "v-detail": detail
        },
    }
</script>

<style scoped>

</style>
